# $Id: GNUMakefile,v 1.1 2009/10/09 07:07:51 pgurumur Exp $
# Copyright (c) 2009 Prabhu Gurumurthy <pgurumur@gmail.com>
#  
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#  
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 
#
CC		:= gcc
PROG	:=	tcelsh
SRCS	:= $(wildcard *.c)
UNAME	:= $(shell uname)
OBJS	:= $(SRCS:.c=.o)

CFLAGS 	:= -fPIC -W -Wall -Wstrict-prototypes -Wmissing-prototypes -g
CFLAGS	+= -Wmissing-declarations -Wpointer-arith -Wcast-qual -Wsign-compare
CFLAGS	+= -I. -I/usr/local/include -fPIE 

ifeq ($(UNAME), Darwin)
CFLAGS	+= -I/System/Library/Frameworks/Tk.framework/Headers/
CFLAGS	+= -I/System/Library/Frameworks/Tcl.framework/Headers/
endif

CFLAGS	+= -I/opt/local/include

ifeq ($(UNAME), Darwin)
LDFLAGS	:= -L/opt/local/lib -lSystem 
else
LDFLAGS	:= -L/opt/local/lib
endif

ifeq ($(UNAME), Linux)
LDFLAGS	+= -ledit -lncurses -ltcl8.5
else
LDFLAGS	+= -ledit -lcurses
endif

ifeq ($(UNAME), Darwin)
FRAME		:= -framework CoreServices -framework Tcl -framework Tk
FRAME		+= -framework ApplicationServices -framework Carbon
else
FRAME		:=
endif

RM		:= /bin/rm -f
LN		:= /bin/ln

all : $(PROG)

$(PROG): $(OBJS)
	@echo "building $@"
	@${CC} -pie -fpic ${FRAME} ${LDFLAGS} -o $@ $^ 

.c.o:
	@echo "compiling $<"
	@${CC} ${CFLAGS} -c $<

clean:
	@echo "cleaning: ${PROG}, ${OBJS} "
	@${RM} ${PROG} ${OBJS} 
